<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
	session_start();
	$dbconn = pg_connect("host=localhost port=5432 dbname=CinemaEnri user=postgres password=Quie1hoh");
	if (!$dbconn){
			die("Errore di connessione al database" . pg_last_error());
	}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="Css/screen.css" rel="stylesheet" type="text/css" media="screen"/>
<script language="JavaScript" type="text/JavaScript" src="Function.js" ></script>
<title>Cinema Enri - Inserimento Film</title>
</head>

<body>
<div id="logo"><img src="Images/Logo.jpg" width="220" height="100"/></div>
        <div id="Header">
             <div id="cerca">
                
            </div>
        </div>
        <div id="main">
            <div id="menu">
                <ul>
                	<div id="infoCinema">
                    	<div class="titolo">Info Cinema</div>
                        <li><a href="Index.php">Home</a></li>
                        <li><a href="Programmazione.php">Programmazione</a></li>
                    </div>
                     <?php
						$user=$_SESSION['User'];
						$admin=$_SESSION['Admin'];
						if (isset($user)){
					?>
                    <div id="utente">
                    	<div class="titolo">Servizi Utente</div>
                        <li><a href="Prenotazioni.php">Prenota un film</a></li>
                        <li><a href="PaginaPersonale.php">Pagina Personale</a></li>
                    </div>
                    <?php
						}
						if ($admin=="t"){
					?>
                    <div id="admin">
                    	<div class="titolo">Amministratore</div>
                        <li><a href="InsSpettacoli.php">Inserimento Spettacoli</a></li>
                        <li><a href="ModSpettacoli.php">Modifica Spettacoli</a></li>
                        <li><a href="InsFilm.php">Inserimento Film</a></li>
                        <li><a href="ModFilm.php">Modifica Film</a></li>
                        <li><a href="InsAttori.php">Inserimento Attori</a></li>
                        <li><a href="ModAttori.php">Modifica Attori</a></li>
                        <li><a href="InsProduzioni.php">Inserimento Produzioni</a></li>
                        <li><a href="ModPrenotazioni.php">Modifica Prenotazioni</a></li>
                    </div>
					<?php
						}
					?>
                <ul>
            </div>
            <div id="path">
            </div>
            <div id="content">
            	<h1>INSERIMENTO FILM</h1>
            	<?php
				 $admin=$_SESSION['Admin'];
				 if ($admin=="t"){
				?>
                <div id="error"></div>
                <form action="InsFilmRiuscito.php" name="film" method="post">
                	<h2>Titolo: </h2> <input type="text" name="titolo" class="textfield"/>
                    
                    <?php
						$qry = 'SELECT * FROM "tblCast" ORDER BY "Cognome", "Nome"';
						$result = pg_query($dbconn, $qry);
						echo "<h2>Regista: </h2> <select name=regista class=textfield>";
						echo "<option value=0 >------</option>";
						while($riga = pg_fetch_assoc($result)) {
							$reg=$riga['Cognome'] . ", " . $riga['Nome'];
							echo "<option value=".$riga['ID'].">".$reg."</option>";
						}
						echo "</select>";	
						
						$qry = 'SELECT * FROM "tblCast" ORDER BY "Cognome", "Nome"';
						$result = pg_query($dbconn, $qry);
						echo '<h2>Attori: </h2><div id="Attori">';
						echo '<label id="labelAttore1"><select name=attore1 class=orario>';
						echo "<option value=0 >------</option>";
						while($riga = pg_fetch_assoc($result)) {
							$attore=$riga['Cognome'] . ", " . $riga['Nome'];
							echo "<option value=".$riga['ID'].">".$attore."</option>";
						}
						echo "</select></label><br /><br />";
						echo "<input type=button id=bottone value='Inserisci Attore' onclick=aggiungiAttore(); /></div><br />";
											
						$qry = 'SELECT * FROM "tblProduzioni"';
						$result = pg_query($dbconn, $qry);
						echo "<h2>Produzioni: </h2><select name=produzione class=textfield>";
						echo "<option value=0 >------</option>";
						while($riga = pg_fetch_assoc($result)) {
							echo "<option value=".$riga['ID'].">".$riga['Nome']."</option>";
						}
						echo "</select>";
					?>
                    <h2>Durata: </h2><input type="text" name="durata" class="textfield"/>
                    
                    <?php 
						$qry = 'SELECT * FROM "tblGeneri"';
						$result = pg_query($dbconn, $qry);
						echo "<h2>Genere:  </h2><select name=genere class=textfield>";
						while($riga = pg_fetch_assoc($result)) {
							echo '<option value="'.$riga['Nome'].'">'.$riga['Nome'].'</option>';
						}
						echo "</select>";
						
						$anno=1930;
						$date = getdate();
						echo "<h2>Anno: </h2><select name=anno class=textfield>";
							while ($anno<=$date['year']){
								echo "<option value=".$anno.">".$anno."</option>";
								$anno=$anno+1;
							}
						echo "</select>";
					
					?>
                    
                    <h2>Nazionalità: </h2><input type="text" name="nazione" class="textfield" />
                    <h2>Descrizione: </h2><textarea name="descrizione" class="textArea" ></textarea>
                    <h2>Sito ufficiale: </h2><input type="text" name="sito" class="textfield" />
                    <h2>Trailer: </h2><input type="text" name="trailer" class="textfield" />
                    
                    <?php
					
					if ($handle = opendir('Images/Film')) { 
  						echo "<h2>Immagine: </h2><select name=immagine class=textfield onchange=Imgpreview(this);>";
						echo "<option value= >------</option>";
  					 	while (false !== ($file = readdir($handle))) {  
      				 		if ( $file == ".." || $file == "." || $file == ".svn") continue;
								echo "<option value=".$file.">".$file."</option>";
   						} 
						echo "</select>";
  						closedir($handle);  
					} 
 
					?>
                    <div id="preview"></div>
                    <h2>3D: </h2><input type="checkbox" name="3d" class="textfield" />
                    <input type="submit" value="Inserisci" />
                </form>
                
                <?php
				 }else{
					echo "Accesso vietato alla pagina"; 
				 }
                ?>
            </div>
            
            <div id="menuDestro">
                <div id="login" >
                	<?php
						$user=$_SESSION['User'];
					 	if (isset($user)){
								echo "<h2>Stato</h2>";
								echo "<h3>Benvenuto ".$user."</h3>";
								echo "<a href=LogOut.php>LogOut</a>";
						}else{
					?>
                	<h2>Login</h2>
                	<form action="Index.php" method="post">
                    	Username:<input type="text" name="Username" />
                        Password:<input type="password" name="Password" />
                        <input type="submit" value="Login" />
                         Se non sei registrato: <a href="Registrazione.php" >Registrati</a>
                    </form>
                   <?php
						}
				   ?>
                </div>
            </div>
       </div>
</div>



</body>
</html>